package dxn.nl.file.biz.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import dxn.nl.file.biz.po.FileExportApplyDetail;
import dxn.nl.file.biz.po.FileImportFileDetail;
import dxn.nl.file.biz.vo.CsImportFileBaseVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface ExcelImportDao extends BaseMapper<FileImportFileDetail> {

    @Update("update file_import_detail " +
            "set statusCode=0,consumer_status=0,consumer_thread =consumer_thread-1 " +
            "where id=#{id}")
    int updateCanConsume(CsImportFileBaseVo applyDetail);

    @Select("select t1.id,t1.mode_code,t1.version_no \n" +
            "from file_export_apply t1 \n" +
            "left join consumer_info t2 on t1.id=t2.id and t2.type_code=10 \n" +
            "where t1.apply_time> DATE_SUB(NOW(), INTERVAL 1 DAY) and t1.tag=#{tag} \n" +
            "and (t2.consumer_status is null or \n" +
            "(t2.consumer_status=0 and t2.consumer_count<16 and t2.consumer_thread is null))")
    List<FileImportFileDetail> selectConsumeList(@Param("tag") String tag);
}
